package com.cytech.cloudclinic.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.core.content.ContextCompat;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.bean.UploadImage;

import java.util.List;

public class SelectImageAdapter extends BaseQuickAdapter<UploadImage, BaseViewHolder> {
    public SelectImageAdapter(List<UploadImage> data) {
        super(R.layout.item_select_image, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, UploadImage uploadImage) {
        ImageView selectImage = baseViewHolder.getView(R.id.iv_common_select);
        if(uploadImage.localUri!=null){
            Glide.with(getContext()).load(uploadImage.localUri).into(selectImage);
        }else if(!TextUtils.isEmpty(uploadImage.url)){
            Glide.with(getContext()).load(uploadImage.url).into(selectImage);
        }else{
            selectImage.setImageDrawable(ContextCompat.getDrawable(getContext(),R.mipmap.icon_add_image));
        }

        if(TextUtils.isEmpty(uploadImage.url)&&uploadImage.localUri==null){
            baseViewHolder.setVisible(R.id.iv_common_delete,false);
        }else{
            baseViewHolder.setVisible(R.id.iv_common_delete,true);
        }
    }
}
